package com.michael.study.jetpack.module.user

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.michael.study.jetpack.R
import com.michael.study.jetpack.bean.User
import kotlinx.android.synthetic.main.activity_user.*

/**
 * Description:
 *
 * Created by liuguoquan on 2020/3/18 17:24.
 */
class UserProfileActivity : AppCompatActivity(), View.OnClickListener {

    private lateinit var model: UserProfileViewModel
    private lateinit var btn_user:TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_user)
        model = ViewModelProvider(this).get(UserProfileViewModel::class.java)

        model.users.observe(this, Observer {
                users ->
            Log.d("lgq", "size = " + users.size)
            users.forEach { it ->
                Log.d("lgq", it.toString())
            }
        })
        btn_user = findViewById(R.id.btn_user);
        btn_user.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        if (v?.id == R.id.btn_user) {
            model.getUser()
        }
    }
}